<?php
# @Author: yongleicheng <jetox>
# @Date:   2017-11-21T02:58:03+08:00
# @Email:  admin@weiqisheng.cn
# @Project: WQSCMS
# @Filename: Index.php
# @Last modified by:   jetox
# @Last modified time: 2017-11-21T03:15:07+08:00
# @Copyright: 微企胜网络科技有限公司




namespace app\api\controller;

use think\Controller;
use clt\Easemob;

define('baserurl', 'http://192.168.0.108/public');
class Index extends Controller
{
    // 获取轮播图
    public function getbanner()
    {
        $table = db('ad');
        $result = $table ->where('type_id', 10) -> select();
        foreach ($result as $v) {
            $v['pic']=baserurl.$v['pic'];
            $data[]=$v;
        }
        return json_encode($data);
    }
    // 获取首页icon导航
    public function getnav()
    {
        $table = db('wp_nav');
        $result = $table ->where('is_show', 1) -> select();
        foreach ($result as $v) {
            $v['iconpath']=baserurl.$v['iconpath'];
            $v['url']="../../".$v['url'];
            $data[]=$v;
        }
        return json_encode($data);
    }
    // 产品中心
    public function getproducts($cid='', $num='', $order='')
    {
        $table = db('product');
        $where= [
            'catid'=>$cid,
            'thumb'=>array('neq','')
        ];
        $result = $table->where($where)->limit($num)->order($order)-> select();
        foreach ($result as $v) {
            $v['thumb']=baserurl.$v['thumb'];
            $data[]=$v;
        }
        return json_encode($data);
    }
    // 案例中心
    public function getcases($cid='', $num='', $order='')
    {
        $table = db('team');
        $where= [
            'catid'=>$cid,
            'thumb'=>array('neq','')
        ];
        $result = $table->where($where)->limit($num)->order($order)-> select();
        foreach ($result as $v) {
            $v['thumb']=baserurl.$v['thumb'];
            $data[]=$v;
        }
        return json_encode($data);
    }
    // 新闻中心
    public function getnews($cid='', $num='', $order='')
    {
        $table = db('article');
        $cid = input('post.cid');
        if ($cid==null) {
            $where= [];
        } else {
            $where= [
                'catid'=>$cid,
            ];
        }

        $result = $table->where($where)->limit($num)->order($order)-> select();
        foreach ($result as $v) {
            $v['thumb']=baserurl.$v['thumb'];
            $v['createtime']=date('Y-m-d', $v['createtime']);
            $data[]=$v;
        }
        return json_encode($data);
    }
    // 获取新闻详情
    public function get_news_Detail($id='')
    {
        $table = db('article');
        $result = $table->field('title,createtime,content,copyfrom')->where('id', $id)->find();
        $result['createtime']=date('Y-m-d', $result['createtime']);
        return json_encode($result);
    }
    //获取所有分类
    public function category()
    {
        $table = db('category');
        $result = $table-> select();
        foreach ($result as $v) {
            $v['active']=false;
            $data[]=$v;
        }
        return json_encode($data);
    }
}
